<?php

require ("sharedResources.php");

$sid = '';
try {
    // We need a SID (session ID) in order to operate
	$sid = login ( 'admin', 'admin' );
	echo 'sid: ' . $sid . PHP_EOL;
	
	// The document should exists otherwhise we get SoapFault
	$docId = 4424482;
	
	$ddp = array ('sid' => $sid, 'docId' => $docId );
	
	$result = $documentClient->getContent ( $ddp );
	// NOTE: It is not recommended to print the binary content of a non txt document 
	//print_r ( $result );
	
	// return contains the binary content
	$content = $result->return;
	
	$myFile = "C:\\tmp\\README.txt";
	$fh = fopen ( $myFile, 'w' ) or die ( "can't open file" );
	fwrite ( $fh, $content );
	fclose ( $fh );

} catch ( SoapFault $e ) {
	print_r ( $e );
}

// Always we need to logout in order to release connection slot
logout ( $sid );
?>
